package com.example.warehousems.event.publisher;

import com.example.warehousems.dao.model.Cargo;
import com.example.warehousems.event.event.CargoInEvent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.stereotype.Component;

@Component
public class CargoInPublisher {
    @Autowired
    private final ApplicationEventPublisher applicationEventPublisher;

    public CargoInPublisher(ApplicationEventPublisher applicationEventPublisher) {
        this.applicationEventPublisher = applicationEventPublisher;
    }

    public Cargo publish(Cargo cargo) {
        CargoInEvent event = new CargoInEvent(cargo);
        applicationEventPublisher.publishEvent(event);
        return cargo;
    }
}
